function getCookie(c_name){
    if (document.cookie.length > 0){
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1){
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
 }


function get_nombre_universidad(){
    $.ajax({ 
            type : "POST", 
            url : 'ajax_univ_request/', 
            data : { 'csrfmiddlewaretoken' : document.getElementsByName('csrfmiddlewaretoken')[0].value, 
                    'pais' : $('#pais').val(), }, 
            success : function(respuesta) { 
                        $('#universidad').html(respuesta)
                     } 
            }
        );
}

function verificarEmail(email){
    new Ajax.Request('ajax_email_verif/', {
    method: 'post',
    requestHeaders: { "X-CSRFToken": getCookie("csrftoken")},
    parameters: $H({'email' :$(email).getValue()}),
        onSuccess: function(transport){
            var e = $('email');
            console.log(transport);

            if (transport.responseText == 'Existe'){
                alert("ERROR! El email con que intenta registrarse ya está siendo utilizado. Por favor cambielo e intente de nuevo.");
                e.setValue('')
            }
        }   
    });
}

function get_indicadores(){
    new Ajax.Request('ajax_ind/', { 
    method: 'post',
    requestHeaders: { "X-CSRFToken": getCookie("csrftoken")},
    parameters: $H({'dimension':document.getElementById('dimension').getValue()}),
    onSuccess: function(transport) {
        var e = $('ind')

        if(transport.responseText)
            e.update(transport.responseText)
    }
    }); // end new Ajax.Request
}

function ajax_message_email() {
    if($("#email").val() == ""){
        $(".correoAlert").html("<div class='alert alert-error'>Ingrese correctamente un email.</div>");
    }else{
        $.ajax({
            type: "POST",
            url: "/plataforma/universidades/ajax_message_email/",
            data: {'email': $("#email").val()},
            cache: false,
            success: function(returndata){
                console.log(returndata);
                if(returndata.tipo == "error")
                    $("#result_email").html("<div class='alert alert-error'>"+returndata.message+"</div>");
                else if(returndata.tipo == "exito")
                    $("#result_email").html("<div class='alert alert-success'>"+returndata.message+"</div>");
            }
            });
    }
}